package cn.wqk.rrtf.controller;

import cn.wqk.rrtf.mapper.CourseMapper;
import cn.wqk.rrtf.mapper.ManagerMapper;
import cn.wqk.rrtf.mapper.UserMapper;
import cn.wqk.rrtf.pojo.Course;
import cn.wqk.rrtf.pojo.Teacher;
import cn.wqk.rrtf.pojo.User;
import cn.wqk.rrtf.service.CourseService;
<<<<<<< HEAD
import cn.wqk.rrtf.service.TeacherService;
=======
>>>>>>> de7ea899210850f410696990fecdc7a7fe9cc7bc
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 龚大磊
 * @Date: 2020/07/17/00:01
 * @Description:
 */
@Controller
public class CourseController {
    @Autowired
    private CourseService courseService;
    @Autowired
<<<<<<< HEAD
    private TeacherService teacherService;
=======
    private CourseMapper courseMapper;
>>>>>>> de7ea899210850f410696990fecdc7a7fe9cc7bc
    @RequestMapping("/pubCourse")
    public String toIndex(Model model){
        List<Course> courseList = courseService.selectAllCourse();
        model.addAttribute("courseList",courseList);
        return "pubCourse";
    }
    @RequestMapping("/courseDetail")
    public String toCourseDetail(Integer courseId,
                                 Model model){
        Course course = courseService.selectCourseByCourseId(courseId);
        Teacher teacher = teacherService.searchTeacherByCourseId(courseId);
        model.addAttribute("course",course);
        model.addAttribute("teacher",teacher);
        return "courseDetail";
    }
    @RequestMapping("/details_clazz")
    public String toClazz(){
        return "details_clazz";
    }
    @RequestMapping("/details_teach")
    public String toTeach(){
        return "details_teach";
    }

    @RequestMapping("/tobaom")
    public String tobaom(Integer courseId,
                         Model model,
                         HttpServletResponse response) throws IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        out.print("<script type='text/javascript'>alert('您已报名成功!');</script>");
        Course course = courseService.selectCourseByCourseId(courseId);
        model.addAttribute("course",course);
        return "courseDetail";
    }
}
